package odl;

import java.util.Vector;

public class Operation extends OdlElement {
	private Vector<Parameter> parameters;
	private String type;
	public Operation(String _name) {
		super(_name);
		parameters = new Vector<Parameter>();
	}
	
	public boolean equals(Operation o){
		boolean res = false;
		if (o.type.equals(this.type) 
				&& o.getName().equals(this.getName()) 
				&& o.numberOfParameters() == this.numberOfParameters()){
			res = true;
			Vector<Parameter> param = o.getParameters();
			for (int i = 0; res && i<this.numberOfParameters();i++){
				res &= param.get(i).equals(this.parameters.get(i));
			}
		}
		return res;
	}
	
	/**
	 * @return the parameters
	 */
	public Vector<Parameter> getParameters() {
		return parameters;
	}

	public int numberOfParameters(){
		return parameters.size();
	}
	
	public Operation(String _name, String _type) {
		super(_name);
		parameters = new Vector<Parameter>();
		type = _type;
	}
	
	public void addParameter(Parameter p){
		parameters.add(p);
	}
	public Vector<String> getDetails(){
		Vector<String> v = new Vector<String>();
		v.add("Type : "+type);
		return v;
	}
	
	public Parameter getParameter(String s)
	{
		for(Parameter pa : parameters)
		{
			if(pa.getName().equals(s))
				return pa;
		}
		return null;
			
	}
	
	public Vector<String> getParametersNames(){
		Vector<String> res = new Vector<String>();
		for (Parameter pa : parameters)
		{
			res.add(pa.getName());
		}
		return res;
	}
	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}
	
	/**
	 * @param type the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}
	
	
}
